Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
Removing "www." from search query

Currently I'm removing https:// and http:// with following code:

$r=\Input::get('searchQuery');
        
        $Query = preg_replace( "#^[^:/.]*[:/]+#i", "", $r);
        $Query=rtrim($Query, "/");

I need to remove www. as well. What should I add to the code inorder to remove www.
Eg: When I search for https://www.example.com/ It should only search for example.com

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

It is really easy, you can use preg_replace with a simple regex:

$query = preg_replace('/^((http:\/\/|https:\/\/)?(www\.)?)/i', '', $text);

See this example, so you can understand my regex.

over 4 years ago · Santiago Trujillo Relatório

0

The following regex works on any string with an optional "http(s)", "www." and trailing slash:

$r=\Input::get('searchQuery');
$Query = preg_replace('/^(https?\:\/\/)?(www.)?|\/$/', "", $r);

How it works:

^ start of the string.

(https?\:\/\/)? optionally match "http(s)://" (the "s" is also optional).

(www.)? optionally match: "www.".

|\/$ match "/" if it is the last character of the string.

over 4 years ago · Santiago Trujillo Relatório

0

You can use Laravel Helpers Method preg_replace_array. preg_replace_array function replaces a given pattern in the string sequentially useing an array:

$string = 'https://www.example.com/'
$query = preg_replace_array('#^[^:/.]*[:/www.?]+#i', [''], $string); // example.com/
$query = rtrim($query, '/'); // example.com

Input: https://www.example.com/
Output: example.com

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda